/**
 * 
 */
package leetCode;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @author zhongfang
 *
 */
public class ValidSquare {
    public static boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
    	HashSet<Integer> dists=new HashSet<>();
    	dists.add(getDist(p1,p2));
    	dists.add(getDist(p1, p3));
    	dists.add(getDist(p1, p4));
    	dists.add(getDist(p2, p3));
    	dists.add(getDist(p2, p4));
    	dists.add(getDist(p3, p4));
    	
    	if(dists.size()!=2){
    		return false;
    	}
    	Iterator<Integer> iterator=dists.iterator();
    	
    	int a=iterator.next();
    	int b=iterator.next();
    	
    	if(a==b*2||b==a*2){
    		return true;
    	}
    	return false;
    }
	private static Integer getDist(int[] p1, int[] p2) {
		return (p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1]);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[][] p4={{5,0},{5,4},{0,4},{0,0}};
		System.out.println(validSquare(p4[0], p4[1], p4[3], p4[2]));
	}

}
